package com.xc.freeapp.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.github.miemiedev.mybatis.paginator.domain.PageBounds;
import com.xc.freeapp.dao.VaccinepersonDao;
import com.xc.freeapp.dao.dataSource.DBContextHolder;
import com.xc.freeapp.entity.Vaccineperson;
import com.xc.freeapp.exception.BaseException;
import com.xc.freeapp.service.VaccinepersonService;
import com.xc.freeapp.util.Constant;
import com.xc.freeapp.util.DateUtils;
import com.xc.freeapp.util.JsonUtil;
@Service
public class VaccinepersonServiceImpl implements VaccinepersonService {
	@Autowired
	VaccinepersonDao vaccinepersonDao;
	
	public Vaccineperson selectByPrimaryKey(Integer id) throws BaseException{
		return vaccinepersonDao.selectByPrimaryKey(id);
	}
	
	public boolean addVaccineperson(Vaccineperson vaccineperson) throws BaseException {
		DBContextHolder.switchDataSourceRW();//切换数据源
		try {
			
			vaccineperson.setCreatetime(DateUtils.getDate());

			vaccineperson.setUpdatetime(DateUtils.getDate());
			vaccinepersonDao.insert(vaccineperson);
		} catch (NumberFormatException e) {
			// TODO Auto-generated catch block
		
			throw new BaseException(Constant.VER_NOTNULL);
		}
		return true;
	}
	public boolean updateVaccineperson(Vaccineperson vaccineperson) throws BaseException {
		DBContextHolder.switchDataSourceRW();//切换数据源
		try {

			vaccineperson.setUpdatetime(DateUtils.getDate());
			vaccinepersonDao.updateByPrimaryKey(vaccineperson);
		} catch (NumberFormatException e) {
			// TODO Auto-generated catch block
		
			throw new BaseException(Constant.VER_NOTNULL);
		}
		return true;
	}

	public List<Vaccineperson> getVaccineperson(Map<String,String> map,PageBounds pageBounds) throws BaseException{
		DBContextHolder.switchDataSourceRW();//切换数据源
		String userid =map.get("userId");
		List<Vaccineperson>  vaccinepersons= vaccinepersonDao.selectByUserid(Integer.parseInt(userid), pageBounds);
		return vaccinepersons;
	}
	public Boolean delVaccineperson(Integer id) throws BaseException{
		DBContextHolder.switchDataSourceRW();//切换数据源
		vaccinepersonDao.deleteByPrimaryKey(id);
		return true;
	}

}
